package Service.Admin.Imp;

import Dao.Admin.TitleManagementDao;
import Dao.DaoFactory;
import Entity.MyTableData;
import Entity.Role.Student;
import Entity.TitleAndPaper.Title;
import Service.Admin.TitleManagementService;
import Util.DBUtil;

import java.sql.Connection;
import java.util.List;

public class TitleManagementServiceImp implements TitleManagementService {
    private TitleManagementDao titleManagementDao;
    private Connection conn;

    public TitleManagementServiceImp(){
        conn = DBUtil.getConnByDruid();
        titleManagementDao = DaoFactory.getInstance("titleManagementDao");
    }

    @Override
    public MyTableData getStudentWithoutTeacher(){
        List<Student> stus = titleManagementDao.getStuWithoutTea(conn);
        DBUtil.closeConn(conn);
        return new MyTableData(0,"",stus.size(),stus);
    }

    @Override
    public Boolean teacherAssign(String tno, String sno){
        boolean flag = titleManagementDao.teacherAssign(tno,sno,conn) == 1;
        DBUtil.closeConn(conn);
        return flag;
    }

    @Override
    public MyTableData adminGetAllTitles(){
        List<Title> titles = titleManagementDao.adminGetAllTitles(conn);
        DBUtil.closeConn(conn);
        return new MyTableData(0,"",titles.size(),titles);
    }
}
